﻿#region

using System;
using CuongHanh.DAL;
using CuongHanh.Models;

#endregion

namespace CuongHanh.Service
{
    public class VirtualDataService
    {
        public static void CreateProductByBranch(int branchId)
        {
            Random r = new Random();
            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                int cacount = r.Next(6,
                        9);
                for (int i = 0; i < cacount; i++)
                {
                    var category = new Category()
                                   {
                                           NameVi = string.Format("Danh Muc {0}",
                                                   i),
                                           NameEn = string.Format("Category {0}",
                                                   i),
                                           BranchId = branchId,
                                           Invisible = false,
                                           Inactive = false,
                                           Code = string.Format("Code-{0}",
                                                   i),
                                           No = i + 1,
                                           LastModified = DateTime.Now,NameZh = string.Empty

                                   };
                    unitOfWork.Insert(category);
                    unitOfWork.Save();
                    int subCount = r.Next(3,
                            7);
                    for (int j = 0; j < subCount; j++)
                    {
                        var subCate = new SubCategory()
                                      {
                                              NameVi = string.Format("Danh Muc Con {0}.{1}",
                                                      category.Id,
                                                      j),
                                              NameEn = string.Format("Sub Category {0}.{1}",
                                                      category.Id,
                                                      j),
                                              BranchId = branchId,
                                              Invisible = false,
                                              Inactive = false,
                                              Code = string.Format("Code-{0}.{1}",
                                                      category.Id, j),
                                              No = i + 1,
                                              LastModified = DateTime.Now,
                                              CategoryId = category.Id,
                                              NameZh = string.Empty

                                      };
                        unitOfWork.Insert(subCate);
                        unitOfWork.Save();

                        int procount = r.Next(4,
                                12);
                        for (int k = 0; k < procount; k++)
                        {
                            var product = new Product()
                                          {
                                                  NameVi = string.Format("San Pham {0}.{1}.{2}",
                                                          category.Id,
                                                          subCate.Id,
                                                          k),
                                                  NameEn = string.Format("Product {0}.{1}.{2}",
                                                          category.Id,
                                                          subCate.Id,
                                                          k),
                                                  Image = string.Format("{0}.jpeg",
                                                          r.Next(1,
                                                                  13)),
                                                  CreateDate = DateTime.Now,
                                                  Code = string.Format("Code-{0}.{1}.{2}",
                                                          category.Id,
                                                          subCate.Id,
                                                          k),
                                                  Inactive = false,
                                                  BranchId = branchId,
                                                  Invisible = false,
                                                  BestSaler = false,
                                                  CategoryId = category.Id,
                                                  SubCategoryId = subCate.Id,
                                                  New = false,
                                                  Price = r.Next(123,
                                                          789) * 1000,
                                                  SaleOff = 20,
                                                  LastModified = DateTime.Now,
                                                  Article = string.Format("Bai viet {0}.{1}.{2}",
                                                          category.Id,
                                                          subCate.Id,
                                                          k),
                                                  IsShowIndex = true,
                                                  NameZh = string.Empty
                                          };
                            unitOfWork.Insert(product);
                            unitOfWork.Save();
                            int coutImage = r.Next(0,
                                    5);
                            for (int l = 0; l < coutImage; l++)
                            {
                                unitOfWork.Insert(new ProductImage()
                                                  {
                                                          Image = string.Format("{0}.jpeg",
                                                          r.Next(1,
                                                                  13)),
                                                                  Inactive = false,
                                                                  LastModified = DateTime.Now,
                                                                  ProductId = product.Id
                                                  });
                            }
                        }
                    }
                }
            }
        }
    }
}
